<template>
  <div>
    <transition name="confirm-fade">
      <div class="confirm" v-show="showFlag" @click.stop style="position: relative;z-index: 2012;">
        <div class="sgmw-dialog" :class="[{onlyTitle: title && !text },{onlyText: !title && text},{titleText: title && text}]" style="z-index: 2013;">
          <div class="sgmw-dialog__header" v-if="title">{{title}}</div>
          <div class="sgmw-dialog__content" v-if="text">
            <div class="sgmw-dialog__message sgmw-dialog__message-has-title">{{text}}</div>
          </div>
          <div class="sgmw-dialog__footer sgmw-dialog__footer-buttons sgmw-hairline-top">
            <button class="sgmw-button sgmw-button-default sgmw-button-large sgmw-dialog__cancel" @click="cancel" v-if="showCancelButton">
              <span class="sgmw-button__text">{{cancelBtnText}}</span>
            </button>
            <button class="sgmw-button sgmw-button-default sgmw-button-large sgmw-dialog__confirm sgmw-hairline-left" @click="confirm">
              <span class="sgmw-button__text">{{confirmBtnText}}</span>
            </button>
          </div>
        </div>
        <div class="sgmw-overlay" style="z-index: 2012;"></div>
      </div>
    </transition>
  </div>

</template>

<script>
  export default {
    props: {
      title: {
        type: String,
        default: ''
      },
      text: {
        type: String,
        default: ''
      },
      confirmBtnText: {
        type: String,
        default: '确定'
      },
      cancelBtnText: {
        type: String,
        default: '取消'
      },
      showCancelButton: {
        type: Boolean,
        default: false
      }
    },
    data() {
      return {
        showFlag: false
      }
    },
    methods: {
      showDialog() {
        this.showFlag = true;
      },
      hideTitleText() {
        this.showFlag = false
      },
      confirm() {
        this.hideTitleText();
        this.$emit('confirm')
      },
      cancel() {
        this.hideTitleText();
        this.$emit('cancel')
      }
    }
  }
</script>

<style scoped lang="less" rel="stylesheet/less">
  @import "~common/less/variable";
  .confirm-fade-enter-active, .confirm-fade-leave-active {
    transition: opacity .5s;
  }
  .confirm-fade-enter, .confirm-fade-leave-to {
    opacity: 0;
  }
  .sgmw-dialog {
    position: fixed;
    top: 50%;
    left: 50%;
    overflow: hidden;
    width: 540px;
    font-size: 32px;
    -webkit-transition: 0.3s;
    transition: 0.3s;
    border-radius: 16px;
    background-color: #fff;
    -webkit-transform: translate3d(-50%, -50%, 0);
    transform: translate3d(-50%, -50%, 0);
    -webkit-backface-visibility: hidden;
    backface-visibility: hidden;
    .sgmw-dialog__header {
      text-align: center;
      color: @C5_800;
      font-size: 32px;
      font-weight: bold;
      letter-spacing: 0.64px;
    }
    .sgmw-dialog__message {
      padding: 50px;
      font-size: 28px;
      line-height: 1.5;
      max-height: 60vh;
      overflow-y: auto;
      text-align: center;
      -webkit-overflow-scrolling: touch;
      white-space: pre-wrap;
      &.sgmw-dialog__message-has-title {
        color: @C5_600;
        padding-top: 24px;
      }
    }
    .sgmw-dialog__footer {
      overflow: hidden;
      -webkit-user-select: none;
      user-select: none;
      .sgmw-button {
        display: inline-block;
        position: relative;
        padding: 0;
        height: 88px;
        line-height: 84px;
        font-size: 32px;
        border-radius: 4px;
        text-align: center;
        box-sizing: border-box;
        -webkit-appearance: none;
        -webkit-text-size-adjust: 100%;
        vertical-align: middle;
        &::before {
          content: " ";
          position: absolute;
          top: 50%;
          left: 50%;
          opacity: 0;
          width: 100%;
          height: 100%;
          border: inherit;
          border-color: #000;
          background-color: #000;
          border-radius: inherit;
          -webkit-transform: translate(-50%, -50%);
          transform: translate(-50%, -50%);
        }
        &.sgmw-button-default {
          color: @C5_600;
          background-color: #fff;
          border: 2px solid #ebedf0;
        }
        &.sgmw-button-large {
          width: 100%;
          height: 96px;
          line-height: 96px;
        }
        &.sgmw-hairline-left::after {
          border-left-width: 2px;
        }
        &.sgmw-dialog__confirm{
          color: @C1_400;
          &:active {
            color: @C1_400;
          }
        }
      }
    }
    .sgmw-dialog__footer-buttons {
      display: -webkit-box;
      display: -webkit-flex;
      display: flex;
      .sgmw-button {
        -webkit-box-flex: 1;
        -webkit-flex: 1;
        flex: 1;
        border:0;
      }
    }

    [class*='sgmw-hairline'] {
      position: relative;
    }
    [class*='sgmw-hairline']::after {
      content: ' ';
      position: absolute;
      pointer-events: none;
      box-sizing: border-box;
      top: -50%;
      left: -50%;
      right: -50%;
      bottom: -50%;
      -webkit-transform: scale(0.5);
      transform: scale(0.5);
      border: 0 solid @gray;
    }
    .sgmw-hairline-top{
      &.sgmw-dialog__footer-buttons{
        .sgmw-button-default{
          border: 0;
        }
      }
      &::after {
        border-top-width: 2px;
      }
    }
  }

  .onlyTitle{
    .sgmw-dialog__header{
      line-height: 48px;
      margin: 48px 32px 48px;
    }
    .sgmw-dialog__content{
      height: 48px;
    }
  }

  .onlyText{
    .sgmw-dialog__content{
      .sgmw-dialog__message{
        padding: 48px 32px 16px;
        line-height: 48px;
        font-size: 32px;
      }
    }
  }

  .titleText{
    .sgmw-dialog__header{
      padding:0 32px;
      line-height: 48px;
      margin-top: 32px;
      margin-bottom: 16px;
    }
    .sgmw-dialog__content{
      .sgmw-dialog__message{
        /*padding:0 32px 16px;*/
        padding:16px 32px 48px;
        line-height: 48px;
        font-size: 32px;
      }
    }
  }

  .sgmw-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.4);
  }

</style>
